<?php

    /**
     * Context
     *
     * Module context manager
     * It's goal is to manage a stack of module context
     *
     * @package      Core
     * @subpackage   Context
     *
     * @license      GNU Lesser General Public Licence see LICENCE-LGPL file or http://www.gnu.org/licenses/lgpl.html
     */
    class Core_Context
    {

    ////////////////////////////////////////////////////////////////////////////
    //                                Variables                               //
    ////////////////////////////////////////////////////////////////////////////

        /**
         * Internal context stack
         *
         * @var array
         */
        protected static $_context = array();

    ////////////////////////////////////////////////////////////////////////////
    //                             Static Methods                             //
    ////////////////////////////////////////////////////////////////////////////

        /**
         * Sets the context to the given module
         *
         * @param        string      $module : the module name
         * @throws       Core_ArgumentException
         * @throws       Core_ArgumentNullException
         * @return       void
         */
        public static function push($module)
        {
            if ($module === null) {
				throw new Core_ArgumentNullException('module is a null reference');
			}

            if (strlen(trim($module)) == 0) {
				throw new Core_ArgumentException('module is a zero-length string');
			}

            array_push(self::$_context, $module);
        }

        /**
         * Cancels the current context and sets the context to the previous module
         *
         * @return       string      the obsolet module name
         */
        public static function pop()
        {
            return array_pop(self::$_context);
        }

        /**
         * Gets the module name of the current context
         *
         * @return       string      name of the current module
         */
        public static function get()
        {
            return end(self::$_context);
        }

        /**
         * Clears the context
         *
         * @return       void
         */
        public static function clear()
        {
            self::$_context = array();
        }
    }
